using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using Spacejock;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using yW5Lib;
using yWriter6.My.Resources;

namespace yWriter6
{
	[DesignerGenerated]
	internal class frmGlobalReplace : Form
	{
		private IContainer components;

		public ToolTip ToolTip1;

		[CompilerGenerated]
		[AccessedThroughProperty("txtLookfor")]
		private TextBox _txtLookfor;

		[CompilerGenerated]
		[AccessedThroughProperty("txtReplaceWith")]
		private TextBox _txtReplaceWith;

		[CompilerGenerated]
		[AccessedThroughProperty("chkCaseSensitive")]
		private CheckBox _chkCaseSensitive;

		[CompilerGenerated]
		[AccessedThroughProperty("chkWholeWordOnly")]
		private CheckBox _chkWholeWordOnly;

		[CompilerGenerated]
		[AccessedThroughProperty("Label1")]
		private Label _Label1;

		[CompilerGenerated]
		[AccessedThroughProperty("Label2")]
		private Label _Label2;

		[CompilerGenerated]
		[AccessedThroughProperty("Frame1")]
		private GroupBox _Frame1;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdOK")]
		private Button _cmdOK;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdExit")]
		private Button _cmdExit;

		[CompilerGenerated]
		[AccessedThroughProperty("Label3")]
		private Label _Label3;

		[CompilerGenerated]
		[AccessedThroughProperty("Label4")]
		private Label _Label4;

		private bool Sensitive;

		private clsProject cProject;

		public virtual TextBox txtLookfor
		{
			[CompilerGenerated]
			get
			{
				return _txtLookfor;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = txtLookfor_Enter;
				TextBox txtLookfor = _txtLookfor;
				if (txtLookfor != null)
				{
					txtLookfor.Enter -= value2;
				}
				_txtLookfor = value;
				txtLookfor = _txtLookfor;
				if (txtLookfor != null)
				{
					txtLookfor.Enter += value2;
				}
			}
		}

		public virtual TextBox txtReplaceWith
		{
			[CompilerGenerated]
			get
			{
				return _txtReplaceWith;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = txtReplaceWith_Enter;
				TextBox txtReplaceWith = _txtReplaceWith;
				if (txtReplaceWith != null)
				{
					txtReplaceWith.Enter -= value2;
				}
				_txtReplaceWith = value;
				txtReplaceWith = _txtReplaceWith;
				if (txtReplaceWith != null)
				{
					txtReplaceWith.Enter += value2;
				}
			}
		}

		public virtual CheckBox chkCaseSensitive
		{
			[CompilerGenerated]
			get
			{
				return _chkCaseSensitive;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = chkCaseSensitive_CheckStateChanged;
				CheckBox chkCaseSensitive = _chkCaseSensitive;
				if (chkCaseSensitive != null)
				{
					chkCaseSensitive.CheckStateChanged -= value2;
				}
				_chkCaseSensitive = value;
				chkCaseSensitive = _chkCaseSensitive;
				if (chkCaseSensitive != null)
				{
					chkCaseSensitive.CheckStateChanged += value2;
				}
			}
		}

		[field: AccessedThroughProperty("chkWholeWordOnly")]
		public virtual CheckBox chkWholeWordOnly
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Label1")]
		public virtual Label Label1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Label2")]
		public virtual Label Label2
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Frame1")]
		public virtual GroupBox Frame1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		public virtual Button cmdOK
		{
			[CompilerGenerated]
			get
			{
				return _cmdOK;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdOK_Click;
				Button cmdOK = _cmdOK;
				if (cmdOK != null)
				{
					cmdOK.Click -= value2;
				}
				_cmdOK = value;
				cmdOK = _cmdOK;
				if (cmdOK != null)
				{
					cmdOK.Click += value2;
				}
			}
		}

		public virtual Button cmdExit
		{
			[CompilerGenerated]
			get
			{
				return _cmdExit;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdExit_Click;
				Button cmdExit = _cmdExit;
				if (cmdExit != null)
				{
					cmdExit.Click -= value2;
				}
				_cmdExit = value;
				cmdExit = _cmdExit;
				if (cmdExit != null)
				{
					cmdExit.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("Label3")]
		public virtual Label Label3
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Label4")]
		internal virtual Label Label4
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool Disposing)
		{
			if (Disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(Disposing);
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			ToolTip1 = new System.Windows.Forms.ToolTip(components);
			Frame1 = new System.Windows.Forms.GroupBox();
			txtLookfor = new System.Windows.Forms.TextBox();
			txtReplaceWith = new System.Windows.Forms.TextBox();
			chkCaseSensitive = new System.Windows.Forms.CheckBox();
			chkWholeWordOnly = new System.Windows.Forms.CheckBox();
			Label3 = new System.Windows.Forms.Label();
			Label1 = new System.Windows.Forms.Label();
			Label2 = new System.Windows.Forms.Label();
			cmdOK = new System.Windows.Forms.Button();
			cmdExit = new System.Windows.Forms.Button();
			Label4 = new System.Windows.Forms.Label();
			Frame1.SuspendLayout();
			SuspendLayout();
			Frame1.BackColor = System.Drawing.Color.Transparent;
			Frame1.Controls.Add(txtLookfor);
			Frame1.Controls.Add(txtReplaceWith);
			Frame1.Controls.Add(chkCaseSensitive);
			Frame1.Controls.Add(chkWholeWordOnly);
			Frame1.Controls.Add(Label3);
			Frame1.Controls.Add(Label1);
			Frame1.Controls.Add(Label2);
			Frame1.Font = new System.Drawing.Font("Arial", 8f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
			Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			Frame1.Location = new System.Drawing.Point(34, 55);
			Frame1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			Frame1.Name = "Frame1";
			Frame1.Padding = new System.Windows.Forms.Padding(0);
			Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			Frame1.Size = new System.Drawing.Size(511, 187);
			Frame1.TabIndex = 6;
			Frame1.TabStop = false;
			txtLookfor.AcceptsReturn = true;
			txtLookfor.BackColor = System.Drawing.SystemColors.Window;
			txtLookfor.Cursor = System.Windows.Forms.Cursors.IBeam;
			txtLookfor.Font = new System.Drawing.Font("Segoe UI", 10f);
			txtLookfor.ForeColor = System.Drawing.SystemColors.WindowText;
			txtLookfor.Location = new System.Drawing.Point(144, 24);
			txtLookfor.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			txtLookfor.MaxLength = 0;
			txtLookfor.Name = "txtLookfor";
			txtLookfor.RightToLeft = System.Windows.Forms.RightToLeft.No;
			txtLookfor.Size = new System.Drawing.Size(349, 25);
			txtLookfor.TabIndex = 0;
			txtReplaceWith.AcceptsReturn = true;
			txtReplaceWith.BackColor = System.Drawing.SystemColors.Window;
			txtReplaceWith.Cursor = System.Windows.Forms.Cursors.IBeam;
			txtReplaceWith.Font = new System.Drawing.Font("Segoe UI", 10f);
			txtReplaceWith.ForeColor = System.Drawing.SystemColors.WindowText;
			txtReplaceWith.Location = new System.Drawing.Point(144, 70);
			txtReplaceWith.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			txtReplaceWith.MaxLength = 0;
			txtReplaceWith.Name = "txtReplaceWith";
			txtReplaceWith.RightToLeft = System.Windows.Forms.RightToLeft.No;
			txtReplaceWith.Size = new System.Drawing.Size(349, 25);
			txtReplaceWith.TabIndex = 1;
			chkCaseSensitive.BackColor = System.Drawing.SystemColors.Control;
			chkCaseSensitive.Checked = true;
			chkCaseSensitive.CheckState = System.Windows.Forms.CheckState.Checked;
			chkCaseSensitive.Cursor = System.Windows.Forms.Cursors.Default;
			chkCaseSensitive.Font = new System.Drawing.Font("Segoe UI", 10f);
			chkCaseSensitive.ForeColor = System.Drawing.SystemColors.ControlText;
			chkCaseSensitive.Location = new System.Drawing.Point(78, 115);
			chkCaseSensitive.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			chkCaseSensitive.Name = "chkCaseSensitive";
			chkCaseSensitive.RightToLeft = System.Windows.Forms.RightToLeft.No;
			chkCaseSensitive.Size = new System.Drawing.Size(147, 26);
			chkCaseSensitive.TabIndex = 2;
			chkCaseSensitive.Text = "Case Sensitive";
			chkCaseSensitive.UseVisualStyleBackColor = true;
			chkWholeWordOnly.BackColor = System.Drawing.SystemColors.Control;
			chkWholeWordOnly.Cursor = System.Windows.Forms.Cursors.Default;
			chkWholeWordOnly.Enabled = false;
			chkWholeWordOnly.Font = new System.Drawing.Font("Segoe UI", 10f);
			chkWholeWordOnly.ForeColor = System.Drawing.SystemColors.ControlText;
			chkWholeWordOnly.Location = new System.Drawing.Point(294, 115);
			chkWholeWordOnly.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			chkWholeWordOnly.Name = "chkWholeWordOnly";
			chkWholeWordOnly.RightToLeft = System.Windows.Forms.RightToLeft.No;
			chkWholeWordOnly.Size = new System.Drawing.Size(180, 26);
			chkWholeWordOnly.TabIndex = 3;
			chkWholeWordOnly.Text = "Whole words only";
			chkWholeWordOnly.UseVisualStyleBackColor = true;
			chkWholeWordOnly.Visible = false;
			Label3.BackColor = System.Drawing.SystemColors.Control;
			Label3.Cursor = System.Windows.Forms.Cursors.Default;
			Label3.Font = new System.Drawing.Font("Segoe UI", 10f);
			Label3.ForeColor = System.Drawing.SystemColors.ControlText;
			Label3.Location = new System.Drawing.Point(3, 155);
			Label3.Name = "Label3";
			Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			Label3.Size = new System.Drawing.Size(477, 20);
			Label3.TabIndex = 9;
			Label3.Text = "EXAMPLE: Replacing Hal with Bal will also turn Half into Balf";
			Label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			Label1.BackColor = System.Drawing.SystemColors.Control;
			Label1.Cursor = System.Windows.Forms.Cursors.Default;
			Label1.Font = new System.Drawing.Font("Segoe UI", 10f);
			Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			Label1.Location = new System.Drawing.Point(63, 27);
			Label1.Name = "Label1";
			Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			Label1.Size = new System.Drawing.Size(65, 26);
			Label1.TabIndex = 8;
			Label1.Text = "Find:";
			Label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
			Label2.BackColor = System.Drawing.SystemColors.Control;
			Label2.Cursor = System.Windows.Forms.Cursors.Default;
			Label2.Font = new System.Drawing.Font("Segoe UI", 10f);
			Label2.ForeColor = System.Drawing.SystemColors.ControlText;
			Label2.Location = new System.Drawing.Point(33, 73);
			Label2.Name = "Label2";
			Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			Label2.Size = new System.Drawing.Size(95, 22);
			Label2.TabIndex = 7;
			Label2.Text = "Replace With:";
			Label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
			cmdOK.BackColor = System.Drawing.SystemColors.Control;
			cmdOK.Cursor = System.Windows.Forms.Cursors.Default;
			cmdOK.Font = new System.Drawing.Font("Segoe UI", 10f);
			cmdOK.ForeColor = System.Drawing.SystemColors.ControlText;
			cmdOK.Location = new System.Drawing.Point(450, 254);
			cmdOK.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			cmdOK.Name = "cmdOK";
			cmdOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
			cmdOK.Size = new System.Drawing.Size(94, 50);
			cmdOK.TabIndex = 5;
			cmdOK.Text = "OK";
			cmdOK.UseVisualStyleBackColor = true;
			cmdExit.BackColor = System.Drawing.SystemColors.Control;
			cmdExit.Cursor = System.Windows.Forms.Cursors.Default;
			cmdExit.Font = new System.Drawing.Font("Segoe UI", 10f);
			cmdExit.ForeColor = System.Drawing.SystemColors.ControlText;
			cmdExit.Location = new System.Drawing.Point(34, 254);
			cmdExit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			cmdExit.Name = "cmdExit";
			cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			cmdExit.Size = new System.Drawing.Size(94, 50);
			cmdExit.TabIndex = 4;
			cmdExit.Text = "Exit";
			cmdExit.UseVisualStyleBackColor = true;
			Label4.AutoSize = true;
			Label4.ForeColor = System.Drawing.SystemColors.MenuHighlight;
			Label4.Location = new System.Drawing.Point(28, 26);
			Label4.Name = "Label4";
			Label4.Size = new System.Drawing.Size(435, 19);
			Label4.TabIndex = 10;
			Label4.Text = "I recommend you take a full backup before using this (Tools - Backup)";
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 17f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			BackColor = System.Drawing.SystemColors.Control;
			base.ClientSize = new System.Drawing.Size(591, 317);
			base.Controls.Add(Label4);
			base.Controls.Add(Frame1);
			base.Controls.Add(cmdOK);
			base.Controls.Add(cmdExit);
			Cursor = System.Windows.Forms.Cursors.Default;
			Font = new System.Drawing.Font("Segoe UI", 10f);
			base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			base.Location = new System.Drawing.Point(3, 22);
			base.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "frmGlobalReplace";
			RightToLeft = System.Windows.Forms.RightToLeft.No;
			Text = "Global Search and Replace";
			Frame1.ResumeLayout(false);
			Frame1.PerformLayout();
			ResumeLayout(false);
			PerformLayout();
		}

		public frmGlobalReplace(ref clsProject ProjectClass)
		{
			base.Load += frmGlobalReplace_Load;
			InitializeComponent();
			cProject = ProjectClass;
		}

		private void chkCaseSensitive_CheckStateChanged(object eventSender, EventArgs eventArgs)
		{
			ReadCaseSensitive();
		}

		private void cmdExit_Click(object eventSender, EventArgs eventArgs)
		{
			Hide();
		}

		private void cmdOK_Click(object eventSender, EventArgs eventArgs)
		{
			ReadCaseSensitive();
			clsShared.cSubs.BusyMouse();
			clsRTF clsRTF = new clsRTF(ref clsShared.cLog, ref clsShared.cSettings);
			if (cProject.AnyScenesLocked())
			{
				clsShared.cSubs.NormalMouse();
				clsShared.cLang.TransMsgBox("Global search/replace cancelled. One or more scenes are open in edit windows.");
			}
			else
			{
				try
				{
					IEnumerator enumerator = default(IEnumerator);
					int num2 = default(int);
					try
					{
						enumerator = cProject.Scenes.GetEnumerator();
						while (enumerator.MoveNext())
						{
							clsScene clsScene = (clsScene)enumerator.Current;
							if (Strings.InStr(1, clsScene.ConvertedToPlainText(), txtLookfor.Text, CompareMethod.Text) > 0)
							{
								string text = clsRTF.RTFToMarkup(clsScene.TextRTF);
								try
								{
									for (int num = text.IndexOf(txtLookfor.Text); num > 0; num = text.IndexOf(txtLookfor.Text, num + 1))
									{
										num2++;
									}
								}
								catch (Exception ex)
								{
									ProjectData.SetProjectError(ex);
									Exception ex2 = ex;
									clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
									ProjectData.ClearProjectError();
								}
								text = ((!Sensitive) ? Strings.Replace(text, txtLookfor.Text, txtReplaceWith.Text, 1, -1, CompareMethod.Text) : Strings.Replace(text, txtLookfor.Text, txtReplaceWith.Text));
								clsScene.SetMarkup(text);
								if (Sensitive)
								{
									clsScene.DescText = Strings.Replace(clsScene.DescText, txtLookfor.Text, txtReplaceWith.Text);
									clsScene.Title = Strings.Replace(clsScene.Title, txtLookfor.Text, txtReplaceWith.Text);
								}
								else
								{
									clsScene.DescText = Strings.Replace(clsScene.DescText, txtLookfor.Text, txtReplaceWith.Text, 1, -1, CompareMethod.Text);
									clsScene.Title = Strings.Replace(clsScene.Title, txtLookfor.Text, txtReplaceWith.Text, 1, -1, CompareMethod.Text);
								}
								clsScene.SaveRTFV5(cProject.ProjectPath());
							}
							cDelay.RegularDoEvents();
						}
					}
					finally
					{
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
					}
					clsShared.cSubs.NormalMouse();
					clsShared.cLang.TransMsgBox("Replaced @1@ occurrences", MsgBoxStyle.OkOnly, "", Conversions.ToString(num2));
				}
				catch (Exception ex3)
				{
					ProjectData.SetProjectError(ex3);
					Exception ex4 = ex3;
					Interaction.MsgBox("Error during search/replace. Please check the log for more info.");
					clsShared.cLog.AddAction(Information.Err(), MethodBase.GetCurrentMethod());
					ProjectData.ClearProjectError();
				}
				Hide();
			}
		}

		private void frmGlobalReplace_Load(object eventSender, EventArgs eventArgs)
		{
			//Discarded unreachable code: IL_007b, IL_0091, IL_009b, IL_00a8, IL_00da, IL_00dc, IL_00f0, IL_0112
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				base.Icon = Resources.yWriter5_Ico;
				num2 = 3;
				if (Operators.CompareString(clsShared.cLang.CurrentLanguage, "English", TextCompare: false) != 0)
				{
					num2 = 4;
					clsShared.cLang.TranslateForm(this);
				}
				num2 = 5;
				clsShared.cFormFont.SetFormFont(this, clsShared.cSettings.sGet("FormFont", modVariables.DefaultUIFont.Name), clsShared.cSettings.sGet("UIFontSize", modVariables.DefaultUIFont.Size));
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0110: Could not find block for branch target IL_00dc*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		private void txtLookfor_Enter(object eventSender, EventArgs eventArgs)
		{
			clsText cText = clsShared.cText;
			TextBox TextControl = txtLookfor;
			cText.HighlightText(ref TextControl);
			txtLookfor = TextControl;
		}

		private void txtReplaceWith_Enter(object eventSender, EventArgs eventArgs)
		{
			clsText cText = clsShared.cText;
			TextBox TextControl = txtReplaceWith;
			cText.HighlightText(ref TextControl);
			txtReplaceWith = TextControl;
		}

		private void ReadCaseSensitive()
		{
			if (chkCaseSensitive.CheckState == CheckState.Checked)
			{
				Sensitive = true;
			}
			else
			{
				Sensitive = false;
			}
		}
	}
}
